<template>
	<view>
		<uni-popup ref='popup' type="center" :maskClick="false">
			<view class="info-box">
				<view class="box">
					<view class="title">
						奖励金
					</view>
					<view class="input">
						<input :focus="showInput" type="text" v-model="deductibleBalance" @input="MonitInput"/>
					</view>
					<view class="tip-box">
						<view>1.可用奖励金不能超过当前订单应付服务费金额的50% </view>
						<view>2.当前订单最大可用金额为{{maxDeductibleBalance}}元</view>
					</view>
				</view>
				<view class="btn" @click="close">
					确定
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import uniPopup from '@/homeSub/components/uni-popup/uni-popup.vue'
	export default {
		components: {
			uniPopup,
		},
		data() {
			return {
				deductibleBalance: '',
				maxDeductibleBalance: '',
				showInput:false
			}
		},
		onLoad(options) {
			//当前订单总金额
			if (options.busBalance) {
				this.maxDeductibleBalance = options.busBalance * 0.5
			}
			this.open()
			this.showInput=true

		},
		methods: {
			//监听输入
			MonitInput(e) {
				if(e.detail.value>this.maxDeductibleBalance){
					uni.showModal({
						title: '信息提示',
						content: '可用奖励金不能超过当前订单金额的50%',
						showCancel: false
					})
					 setTimeout(() => { this.deductibleBalance='' }, 50)
				}
			},
			open() {
				this.$refs.popup.open()
			},
			close() {
				let pages = getCurrentPages(); //当前页面
				let prevPage = pages[pages.length - 2]; //上一页面
				prevPage.setData({
				    //直接给上一个页面赋值
					
				});
				uni.navigateBack({
				    delta: 1
				});
			}
		}
	}
</script>

<style lang="scss">
	.info-box {
		border-radius: 20rpx;
		width: 702rpx;
		display: flex;
		flex-direction: column;
		background-color: #FFFFFF;
		align-items: center;

		.box {
			padding: 30rpx;
			display: flex;
			flex-direction: column;
			align-items: center;

			.title {
				font-size: 34rpx;
				font-family: PingFang SC-Bold, PingFang SC;
				font-weight: 700;
				color: #303133;
			}

			input {
				width: 576rpx;
				padding: 0 20rpx;
				height: 68rpx;
				border-radius: 10rpx 10rpx 10rpx 10rpx;
				border: 1rpx solid #303133;
				margin: 20rpx 0;
			}

			.tip-box {
				width: 616rpx;
				font-size: 30rpx;
				font-family: PingFang SC-Regular, PingFang SC;
				font-weight: 400;
				color: #303133;
			}
		}
	}

	.btn {
		width: 100%;
		height: 100rpx;
		text-align: center;
		line-height: 100rpx;
		font-size: 30rpx;
		font-weight: 700;
		font-family: PingFang SC-Bold, PingFang SC;
		color: #6DB12E;
		border-top: 1rpx solid #DCDFE6;
	}
</style>